#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
int main()
{
	int a = 0;
	int b = 0;
	while (scanf("%d %d", &a, &b) != EOF)
	{
		if ((0 == a % 4 && a % 100 != 0) || (0 == a % 400))
		{
			int arr1[12] = { 31,29,31,30,31,30,31,31,30,31,30,31 };
			int c = arr1[b - 1];
			printf("%d\n", c);
		}
		else
		{
			int arr2[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
			int d = arr2[b - 1];
			printf("%d\n", d);
		}
	}
	return 0;
}